home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume13 / m4 / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-02-27  |  26.4 KB

  1. Subject:  v13i039:  Public domaind M4 macro processor, Part02/02
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Ozan Yigit <yunexus!oz>
  7. Posting-number: Volume 13, Issue 39
  8. Archive-name: m4/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive, meaning:
  12. # 1. Remove everything above the #! /bin/sh line.
  13. # 2. Save the resulting text in a file.
  14. # 3. Execute the file with /bin/sh (not csh) to create the files:
  15. #    ack.m4
  16. #    hanoi.m4
  17. #    hash.m4
  18. #    sqroot.m4
  19. #    string.m4
  20. #    test.m4
  21. #    README
  22. #    MANIFEST
  23. #    m4.1
  24. export PATH; PATH=/bin:$PATH
  25. echo shar: extracting "'ack.m4'" '(121 characters)'
  26. if test -f 'ack.m4'
  27. then
  28.     echo shar: will not over-write existing file "'ack.m4'"
  29. else
  30. sed 's/^    X//' << \SHAR_EOF > 'ack.m4'
  31.     Xdefine(DECR,`eval($1-1)')
  32.     Xdefine(ack, `ifelse($1,0,incr($2),$2,0,`ack(DECR($1),1)',
  33.     X`ack(DECR($1), ack($1,DECR($2)))')')
  34. SHAR_EOF
  35. if test 121 -ne "`wc -c < 'ack.m4'`"
  36. then
  37.     echo shar: error transmitting "'ack.m4'" '(should have been 121 characters)'
  38. fi
  39. fi # end of overwriting check
  40. echo shar: extracting "'hanoi.m4'" '(215 characters)'
  41. if test -f 'hanoi.m4'
  42. then
  43.     echo shar: will not over-write existing file "'hanoi.m4'"
  44. else
  45. sed 's/^    X//' << \SHAR_EOF > 'hanoi.m4'
  46.     Xdefine(DECR,`eval($1-1)')
  47.     Xdefine(hanoi, `trans(A, B, C, $1)')
  48.     X
  49.     Xdefine(moved,`move disk from $1 to $2
  50.     X')
  51.     X
  52.     Xdefine(trans, `ifelse($4,1,`moved($1,$2)',
  53.     X    `trans($1,$3,$2,DECR($4))moved($1,$2)trans($3,$2,$1,DECR($4))')')
  54. SHAR_EOF
  55. if test 215 -ne "`wc -c < 'hanoi.m4'`"
  56. then
  57.     echo shar: error transmitting "'hanoi.m4'" '(should have been 215 characters)'
  58. fi
  59. fi # end of overwriting check
  60. echo shar: extracting "'hash.m4'" '(425 characters)'
  61. if test -f 'hash.m4'
  62. then
  63.     echo shar: will not over-write existing file "'hash.m4'"
  64. else
  65. sed 's/^    X//' << \SHAR_EOF > 'hash.m4'
  66.     Xdnl    This probably will not run on any m4 that cannot
  67.     Xdnl    handle char constants in eval.
  68.     Xdnl
  69.     Xchangequote(<,>) define(HASHVAL,99) dnl
  70.     Xdefine(hash,<eval(str(substr($1,1),0)%HASHVAL)>) dnl
  71.     Xdefine(str,
  72.     X    <ifelse($1,",$2,
  73.     X        <str(substr(<$1>,1),<eval($2+'substr($1,0,1)')>)>)
  74.     X    >) dnl
  75.     Xdefine(KEYWORD,<$1,hash($1),>) dnl
  76.     Xdefine(TSTART,
  77.     X<struct prehash {
  78.     X    char *keyword;
  79.     X    int   hashval;
  80.     X} keytab[] = {>) dnl
  81.     Xdefine(TEND,<    "",0
  82.     X};>) dnl
  83. SHAR_EOF
  84. if test 425 -ne "`wc -c < 'hash.m4'`"
  85. then
  86.     echo shar: error transmitting "'hash.m4'" '(should have been 425 characters)'
  87. fi
  88. fi # end of overwriting check
  89. echo shar: extracting "'sqroot.m4'" '(238 characters)'
  90. if test -f 'sqroot.m4'
  91. then
  92.     echo shar: will not over-write existing file "'sqroot.m4'"
  93. else
  94. sed 's/^    X//' << \SHAR_EOF > 'sqroot.m4'
  95.     Xdefine(square_root, 
  96.     X    `ifelse(eval($1<0),1,negative-square-root,
  97.     X                 `square_root_aux($1, 1, eval(($1+1)/2))')')
  98.     Xdefine(square_root_aux,
  99.     X    `ifelse($3, $2, $3,
  100.     X        $3, eval($1/$2), $3,
  101.     X        `square_root_aux($1, $3, eval(($3+($1/$3))/2))')')
  102. SHAR_EOF
  103. if test 238 -ne "`wc -c < 'sqroot.m4'`"
  104. then
  105.     echo shar: error transmitting "'sqroot.m4'" '(should have been 238 characters)'
  106. fi
  107. fi # end of overwriting check
  108. echo shar: extracting "'string.m4'" '(204 characters)'
  109. if test -f 'string.m4'
  110. then
  111.     echo shar: will not over-write existing file "'string.m4'"
  112. else
  113. sed 's/^    X//' << \SHAR_EOF > 'string.m4'
  114.     X
  115.     Xdefine(string,`integer $1(len(substr($2,1)))
  116.     Xstr($1,substr($2,1),0)
  117.     Xdata $1(len(substr($2,1)))/EOS/
  118.     X')
  119.     X
  120.     Xdefine(str,`ifelse($2,",,data $1(incr($3))/`LET'substr($2,0,1)/
  121.     X`str($1,substr($2,1),incr($3))')')
  122. SHAR_EOF
  123. if test 204 -ne "`wc -c < 'string.m4'`"
  124. then
  125.     echo shar: error transmitting "'string.m4'" '(should have been 204 characters)'
  126. fi
  127. fi # end of overwriting check
  128. echo shar: extracting "'test.m4'" '(7873 characters)'
  129. if test -f 'test.m4'
  130. then
  131.     echo shar: will not over-write existing file "'test.m4'"
  132. else
  133. sed 's/^    X//' << \SHAR_EOF > 'test.m4'
  134.     X#
  135.     X# test file for mp (not comprehensive)
  136.     X#
  137.     X# include string macros
  138.     X#
  139.     Xinclude(string.m4)
  140.     X#
  141.     X# create some fortrash strings for an even uglier language
  142.     X#
  143.     Xstring(TEXT, "text")
  144.     Xstring(DATA, "data")
  145.     Xstring(BEGIN, "begin")
  146.     Xstring(END, "end")
  147.     Xstring(IF, "if")
  148.     Xstring(THEN, "then")
  149.     Xstring(ELSE, "else")
  150.     Xstring(CASE, "case")
  151.     Xstring(REPEAT, "repeat")
  152.     Xstring(WHILE, "while")
  153.     Xstring(DEFAULT, "default")
  154.     Xstring(UNTIL, "until")
  155.     Xstring(FUNCTION, "function")
  156.     Xstring(PROCEDURE, "procedure")
  157.     Xstring(EXTERNAL, "external")
  158.     Xstring(FORWARD, "forward")
  159.     Xstring(TYPE, "type")
  160.     Xstring(VAR, "var")
  161.     Xstring(CONST, "const")
  162.     Xstring(PROGRAM, "program")
  163.     Xstring(INPUT, "input")
  164.     Xstring(OUTPUT, "output")
  165.     X#
  166.     Xdivert(2)
  167.     Xdiversion #1
  168.     Xdivert(3)
  169.     Xdiversion #2
  170.     Xdivert(4)
  171.     Xdiversion #3
  172.     Xdivert(5)
  173.     Xdiversion #4
  174.     Xdivert(0)
  175.     Xdefine(abc,xxx)
  176.     Xifdef(`abc',defined,undefined)
  177.     X#
  178.     X# v7 m4 does this wrong. The right output is 
  179.     X#     this is A vEry lon sEntEnCE
  180.     X# see m4 documentation for translit.
  181.     X#
  182.     Xtranslit(`this is a very long sentence', abcdefg, ABCDEF)
  183.     X#
  184.     X# include towers-of-hanoi
  185.     X#
  186.     Xinclude(hanoi.m4)
  187.     X#
  188.     X# some reasonable set of disks
  189.     X#
  190.     Xhanoi(6)
  191.     X#
  192.     X# include ackermann's function
  193.     X#
  194.     Xinclude(ack.m4)
  195.     X#
  196.     X# something like (3,3) will blow away un*x m4.
  197.     X#
  198.     Xack(2,3)
  199.     X#
  200.     X# include a square_root function for fixed nums
  201.     X#
  202.     Xinclude(sqroot.m4)
  203.     X#
  204.     X# some square roots.
  205.     X#
  206.     Xsquare_root(15)
  207.     Xsquare_root(100)
  208.     Xsquare_root(-4)
  209.     Xsquare_root(21372)
  210.     X#
  211.     X# some textual material for enjoyment.
  212.     X#
  213.     X[taken from the 'Clemson University Computer Newsletter',
  214.     X September 1981, pp. 6-7]
  215.     X     
  216.     XI am a wizard in the magical Kingdom of Transformation and I
  217.     Xslay dragons for a living.  Actually, I am a systems programmer.
  218.     XOne of the problems with systems programming is explaining to
  219.     Xnon-computer enthusiasts what that is.  All of the terms I use to
  220.     Xdescribe my job are totally meaningless to them.  Usually my response
  221.     Xto questions about my work is to say as little as possible.  For
  222.     Xinstance, if someone asks what happened at work this week, I say
  223.     X"Nothing much" and then I change the subject.
  224.     X     
  225.     XWith the assistance of my brother, a mechanical engineer, I have devised
  226.     Xan analogy that everyone can understand.  The analogy describes the
  227.     X"Kingdom of Transformation" where travelers wander and are magically
  228.     Xtransformed.  This kingdom is the computer and the travelers are information.
  229.     XThe purpose of the computer is to change information to a more meaningful
  230.     Xforma.  The law of conservation applies here:  The computer never creates
  231.     Xand never intentionally destroys data.  With no further ado, let us travel
  232.     Xto the Kingdom of Transformation:
  233.     X     
  234.     XIn a land far, far away, there is a magical kingdom called the Kingdom of
  235.     XTransformation.  A king rules over this land and employs a Council of
  236.     XWizardry.  The main purpose of this kingdom is to provide a way for
  237.     Xneighboring kingdoms to transform citizens into more useful citizens.  This
  238.     Xis done by allowing the citizens to enter the kingdom at one of its ports
  239.     Xand to travel any of the many routes in the kingdom.  They are magically
  240.     Xtransformed along the way.  The income of the Kingdom of Transformation
  241.     Xcomes from the many toll roads within its boundaries.
  242.     X     
  243.     XThe Kingdom of Transformation was created when several kingdoms got
  244.     Xtogether and discovered a mutual need for new talents and abilities for
  245.     Xcitizens.  They employed CTK, Inc. (Creators of Transformation, Inc.) to
  246.     Xcreate this kingdom.  CTK designed the country, its transportation routes,
  247.     Xand its laws of transformation, and created the major highway system.
  248.     X     
  249.     XHazards
  250.     X=======
  251.     X     
  252.     XBecause magic is not truly controllable, CTK invariably, but unknowingly,
  253.     Xcreates dragons.  Dragons are huge fire-breathing beasts which sometimes
  254.     Xinjure or kill travelers.  Fortunately, they do not travel, but always
  255.     Xremain near their den.
  256.     X     
  257.     XOther hazards also exist which are potentially harmful.  As the roads
  258.     Xbecome older and more weatherbeaten, pot-holes will develop, trees will
  259.     Xfall on travelers, etc.  CTK maintenance men are called to fix these
  260.     Xproblems.
  261.     X     
  262.     XWizards
  263.     X=======
  264.     X     
  265.     XThe wizards play a major role in creating and maintaining the kingdom but
  266.     Xget little credit for their work because it is performed secretly.  The
  267.     Xwizards do not wan the workers or travelers to learn their incantations
  268.     Xbecause many laws would be broken and chaos would result.
  269.     X     
  270.     XCTK's grand design is always general enough to be applicable in many
  271.     Xdifferent situations.  As a result, it is often difficult to use.  The
  272.     Xfirst duty of the wizards is to tailor the transformation laws so as to be
  273.     Xmore beneficial and easier to use in their particular environment.
  274.     X     
  275.     XAfter creation of the kingdom, a major duty of the wizards is to search for
  276.     Xand kill dragons.  If travelers do not return on time or if they return
  277.     Xinjured, the ruler of the country contacts the wizards.  If the wizards
  278.     Xdetermine that the injury or death occurred due to the traveler's
  279.     Xnegligence, they provide the traveler's country with additional warnings.
  280.     XIf not, they must determine if the cause was a road hazard or a dragon.  If
  281.     Xthe suspect a road hazard, they call in a CTK maintenance man to locate the
  282.     Xhazard and to eliminate it, as in repairing the pothole in the road.  If
  283.     Xthey think that cause was a dragon, then they must find and slay it.
  284.     X     
  285.     XThe most difficult part of eliminating a dragon is finding it.  Sometimes
  286.     Xthe wizard magically knows where the dragon's lair it, but often the wizard
  287.     Xmust send another traveler along the same route and watch to see where he
  288.     Xdisappears.  This sounds like a failsafe method for finding dragons (and a
  289.     Xsuicide mission for thr traveler) but the second traveler does not always
  290.     Xdisappear.  Some dragons eat any traveler who comes too close; others are
  291.     Xvery picky.
  292.     X     
  293.     XThe wizards may call in CTK who designed the highway system and
  294.     Xtransformation laws to help devise a way to locate the dragon.  CTK also
  295.     Xhelps provide the right spell or incantation to slay the dragon. (There is
  296.     Xno general spell to slay dragons; each dragon must be eliminated with a
  297.     Xdifferent spell.)
  298.     X     
  299.     XBecause neither CTK nor wizards are perfect, spells to not always work
  300.     Xcorrectly.  At best, nothing happens when the wrong spell is uttered.  At
  301.     Xworst, the dragon becomes a much larger dragon or multiplies into several
  302.     Xsmaller ones.  In either case, new spells must be found.
  303.     X     
  304.     XIf all existing dragons are quiet (i.e. have eaten sufficiently), wizards
  305.     Xhave time to do other things.  They hide in castles and practice spells and
  306.     Xincatations.  They also devise shortcuts for travelers and new laws of
  307.     Xtransformation.
  308.     X     
  309.     XChanges in the Kingdom
  310.     X======================
  311.     X     
  312.     XAs new transformation kingdoms are created and old ones are maintained,
  313.     XCTK, Inc. is constantly learning new things.  It learns ways to avoid
  314.     Xcreating some of the dragons that they have previously created.  It also
  315.     Xdiscovers new and better laws of transformation.  As a result, CTK will
  316.     Xperiodically create a new grand design which is far better than the old.
  317.     XThe wizards determine when is a good time to implement this new design.
  318.     XThis is when the tourist season is slow or when no important travelers
  319.     X(VIPs) are to arrive.  The kingdom must be closed for the actual
  320.     Ximplementation and is leter reopened as a new and better place to go.
  321.     X     
  322.     XA final question you might ask is what happens when the number of tourists
  323.     Xbecomes too great for the kingdom to handle in a reasonable period of time
  324.     X(i.e., the tourist lines at the ports are too long).  The Kingdom of
  325.     XTransformation has three options: (1) shorten the paths that a tourist must
  326.     Xtravel, or (2) convince CTK to develop a faster breed of horses so that the
  327.     Xtravelers can finish sooner, or (3) annex more territories so that the
  328.     Xkingdom can handle more travelers.
  329.     X     
  330.     XThus ends the story of the Kingdom of Transformation.  I hope this has
  331.     Xexplained my job to you:  I slay dragons for a living.
  332.     X
  333.     X#
  334.     X#should do an automatic undivert..
  335.     X#
  336. SHAR_EOF
  337. if test 7873 -ne "`wc -c < 'test.m4'`"
  338. then
  339.     echo shar: error transmitting "'test.m4'" '(should have been 7873 characters)'
  340. fi
  341. fi # end of overwriting check
  342. echo shar: extracting "'README'"
  343. if test -f 'README'
  344. then
  345.     echo shar: will not over-write existing file "'README'"
  346. else
  347. cat << \SHAR_EOF > 'README'
  348.     What you have here is a completely PD implementation of
  349.     M4. It was originally written for the GNU project. 
  350.     This version was the last version before a major re-write 
  351.     took place.
  352.  
  353.     Pd M4 is based on software tools macro, as described in the
  354.     two tools books by Kernighan and Plauger. Although some
  355.     serious changes have been made, this version inherits the basic
  356.     design problems of the original, hence the ugliness of the
  357.     underlying code. [GNU version of this processor is re-designed
  358.     in a much cleaner fashion, and is expected to be out before 
  359.     1988. GNU version also includes an extensive texinfo document.]
  360.  
  361.     PDness:
  362.  
  363.     This code *is* PD. You (public) have all the rights to the code. 
  364.     [But this also means you (singular) do not have any *extra*
  365.     rights to the code, hence it is impossible for you to restrict
  366.     the use and distribution of this code in any way.]
  367.  
  368.     Dedication:
  369.  
  370.     This posting is a dedication to an old 750 that started out
  371.     running 4.1BSD and had 1.5 meg, 1 dz11, and 2 Rk07 drives.
  372.     It was named yetti [sic] by accident, and was managed by the
  373.     author until its retirement few months ago. [the name yetti 
  374.     now identifies a different machine]
  375.  
  376.     Distribution + misc:
  377.  
  378.     The distribution includes a small test suite, the sources and
  379.     a man page. texinfo document is not included. The makefile is
  380.     pretty simple. See the makefile for configuration options.
  381.     Try "make time" for some timing comparisons between your un*x
  382.     m4 and the pd m4. [It should be slighly slower than V7 m4, and
  383.     slightly faster than SV m4]. Make sure to set MBIN to indicate
  384.     the location of un*x m4. See the test suite (test.m4) for some
  385.     additional comments about pd m4 vs un*x m4.
  386.  
  387.     Some thoughts:
  388.  
  389.     M4 is a neat macro processor but probably a bit outdated by
  390.     now. It does not need gratuitous additions, or "features", but
  391.     a complete re-write. As it stands, it is powerful enough for
  392.     most macro processing needs. We have, for example, used it to
  393.     build a configuration language for DECNET under VMS. It can
  394.     be a handy software engineering tool under most circumstances,
  395.     and can displace a lot of meaningless little hacks written in
  396.     C, pascal or whatever. [See some net postings for references.]
  397.  
  398.     Suggestions for hacking:
  399.  
  400.     If you want to hack M4 further, you may wish to implement the
  401.     SV m4 "trace" facility, and extended (5-char) Comment/Quote
  402.     definitions. This version also needs some dynamicity for its
  403.     data structures, and the ability to handle multiple file names
  404.     in the command line. If you want to add "features", you may wish
  405.     to first think about implementing the "feature" as an M4 macro.
  406.     If you really want to elevate this processor into a more state-of
  407.     the-art tool, than you should probably re-write it. [But I have
  408.     already done that, so you may wish to wait for the GNU version to
  409.     get a head start.]
  410.  
  411.     Feedback:
  412.  
  413.     If you have any important fixes and/or speed improvements,  I am
  414.     much interested, since my new version inherits some code from this
  415.     version. I am also interested in hearing about any unique applica-
  416.     tions of M4. I am not interested in gratuitous hacks or "neat"
  417.     kitchen-sink features. 
  418.  
  419.     Contact:
  420.  
  421.         Usenet: [decvax|ihnp4]!utzoo!yunexus!oz || 
  422.                 ...seismo!mnetor!yunexus!oz
  423.         Bitnet: oz@[yulibra|yuyetti].BITNET
  424.         Phonet: [416] 736-5257 x 3976
  425.  
  426.  
  427.     enjoy.    oz
  428. SHAR_EOF
  429. fi # end of overwriting check
  430. echo shar: extracting "'MANIFEST'" '(230 characters)'
  431. if test -f 'MANIFEST'
  432. then
  433.     echo shar: will not over-write existing file "'MANIFEST'"
  434. else
  435. sed 's/^    X//' << \SHAR_EOF > 'MANIFEST'
  436.     Xmdef.h    - definitions and structures
  437.     Xmain.c    - this file: driver routines
  438.     Xeval.c    - general macro evaluator
  439.     Xserv.c    - service routines (doxxxx)
  440.     Xmisc.c    - miscellaneous routines
  441.     Xexpr.c    - expression parser
  442.     Xlook.c    - hash table management
  443. SHAR_EOF
  444. if test 230 -ne "`wc -c < 'MANIFEST'`"
  445. then
  446.     echo shar: error transmitting "'MANIFEST'" '(should have been 230 characters)'
  447. fi
  448. fi # end of overwriting check
  449. echo shar: extracting "'m4.1'" '(9644 characters)'
  450. if test -f 'm4.1'
  451. then
  452.     echo shar: will not over-write existing file "'m4.1'"
  453. else
  454. sed 's/^    X//' << \SHAR_EOF > 'm4.1'
  455.     X.TH M4 local "30 Aug 1987"
  456.     X.DA 08 Jan 1986
  457.     X.SH NAME
  458.     Xpd m4 \- macro processor
  459.     X.SH ORIGIN
  460.     XMetaSystems
  461.     X.SH SYNOPSIS
  462.     X.BI m4 "[ options ]"
  463.     X.SH DESCRIPTION
  464.     X.I Pd M4
  465.     Xis a un*x M4 look-alike macro processor
  466.     Xintended as a front end for Ratfor, Pascal, and other languages that do not
  467.     Xhave a built-in macro processing capability.
  468.     XPd M4 reads standard input, the processed text is written on the standard output.
  469.     X.PP
  470.     XThe options and their effects are as follows:
  471.     X.TP
  472.     X\f3\-D\fP\f2name\^\fP[\f3=\fP\f2val\^\fP]
  473.     XDefines
  474.     X.I name
  475.     Xto
  476.     X.I val
  477.     Xor to null in
  478.     X.IR val 's
  479.     Xabsence.
  480.     X.TP
  481.     X.BI \-U name
  482.     Xundefines
  483.     X.IR name .
  484.     X.PP
  485.     XMacro calls
  486.     Xhave the form:
  487.     X.PP
  488.     X.RS
  489.     X\fBname\fI(arg1,arg2, .\|.\|., argn)\fR
  490.     X.RE
  491.     X.PP
  492.     XThe
  493.     X.B (
  494.     Xmust immediately follow the name of the macro.
  495.     XIf the name of a defined macro is not followed by a
  496.     X.BR ( ,
  497.     Xit is taken to be a call of that macro with no arguments, i.e. name().
  498.     XPotential macro names consist of alphabetic letters and digits.
  499.     X.PP
  500.     XLeading unquoted blanks, tabs and newlines are ignored while collecting 
  501.     Xarguments.
  502.     XLeft and right single quotes are used to quote strings.
  503.     XThe value of a quoted string is the string stripped of the quotes.
  504.     X.PP
  505.     XWhen a macro name is recognized,
  506.     Xits arguments are collected by searching for a matching
  507.     X.BR ) .
  508.     XIf fewer arguments are supplied than are in the macro definition,
  509.     Xthe trailing arguments are taken to be null.
  510.     XMacro evaluation proceeds normally during the collection of the arguments,
  511.     Xand any commas or right parentheses
  512.     Xwhich happen to turn up within the value of a nested
  513.     Xcall are as effective as those in the original input text. (This is typically
  514.     Xreferred as
  515.     X.I inside-out
  516.     Xmacro expansion.)
  517.     XAfter argument collection,
  518.     Xthe value of the macro is pushed back onto the input stream
  519.     Xand rescanned.
  520.     X.PP
  521.     X.I Pd M4
  522.     Xmakes available the following built-in macros.
  523.     XThey may be redefined, but once this is done the original meaning is lost.
  524.     XTheir values are null unless otherwise stated.
  525.     X.de MC
  526.     X.TP 14
  527.     X.B \\$1
  528.     Xusage: \\fI\\$1\\$2\\fR
  529.     X.br
  530.     X..
  531.     X.MC define "(name [, val])"
  532.     Xthe second argument is installed as the value of the macro
  533.     Xwhose name is the first argument. If there is no second argument,
  534.     Xthe value is null.
  535.     XEach occurrence of
  536.     X.BI $ n
  537.     Xin the replacement text,
  538.     Xwhere
  539.     X.I n
  540.     Xis a digit,
  541.     Xis replaced by the
  542.     X.IR n -th
  543.     Xargument.
  544.     XArgument 0 is the name of the macro;
  545.     Xmissing arguments are replaced by the null string.
  546.     X.MC defn "(name [, name ...])
  547.     Xreturns the quoted definition of its argument(s). Useful in renaming
  548.     Xmacros.
  549.     X.MC undefine "(name [, name ...])"
  550.     Xremoves the definition of the macro(s) named. If there is
  551.     Xmore than one definition for the named macro, (due to previous use of
  552.     X.IR pushdef ) 
  553.     Xall definitions are removed.
  554.     X.MC pushdef "(name [, val])"
  555.     Xlike
  556.     X.IR define ,
  557.     Xbut saves any previous definition by stacking the current definition.
  558.     X.MC popdef "(name [, name ...])"
  559.     Xremoves current definition of its argument(s),
  560.     Xexposing the previous one if any.
  561.     X.MC ifdef "(name, if-def [, ifnot-def])"
  562.     Xif the first argument is defined, the value is the second argument, 
  563.     Xotherwise the third.
  564.     XIf there is no third argument, the value is null.
  565.     XA word indicating the current operating system is predefined.
  566.     X(e.g.
  567.     X.I unix
  568.     Xor
  569.     X.IR vms )
  570.     X.MC shift "(arg, arg, arg, ...)"
  571.     Xreturns all but its first argument.
  572.     XThe other arguments are quoted and pushed back with
  573.     Xcommas in between.
  574.     XThe quoting nullifies the effect of the extra scan that
  575.     Xwill subsequently be performed.
  576.     X.MC changequote "(lqchar, rqchar)"
  577.     Xchange quote symbols to the first and second arguments.
  578.     XWith no arguments, the quotes are reset back to the default
  579.     Xcharacters. (i.e., \*`\|\*').
  580.     X.MC changecom "(lcchar, rcchar)"
  581.     Xchange left and right comment markers from the default
  582.     X.B #
  583.     Xand 
  584.     X.BR newline .
  585.     XWith no arguments, the comment mechanism is reset back to 
  586.     Xthe default characters.
  587.     XWith one argument, the left marker becomes the argument and
  588.     Xthe right marker becomes newline.
  589.     XWith two arguments, both markers are affected.
  590.     X.MC divert "(divnum)"
  591.     X.I m4
  592.     Xmaintains 10 output streams,
  593.     Xnumbered 0-9.  initially stream 0 is the current stream. 
  594.     XThe
  595.     X.I divert
  596.     Xmacro changes the current output stream to its (digit-string)
  597.     Xargument.
  598.     XOutput diverted to a stream other than 0 through 9
  599.     Xdisappears into bitbucket.
  600.     X.MC undivert "([divnum [, divnum ...]])"
  601.     Xcauses immediate output of text from diversions named as
  602.     Xargument(s), or all diversions if no argument.
  603.     XText may be undiverted into another diversion.
  604.     XUndiverting discards the diverted text. At the end of input processing,
  605.     X.I M4
  606.     Xforces an automatic
  607.     X.IR undivert ,
  608.     Xunless
  609.     X.I m4wrap
  610.     Xis defined.
  611.     X.MC divnum "()"
  612.     Xreturns the value of the current output stream.
  613.     X.MC dnl "()"
  614.     Xreads and discards characters up to and including the next newline.
  615.     X.MC ifelse "(arg, arg, if-same [, ifnot-same | arg, arg ...])"
  616.     Xhas three or more arguments.
  617.     XIf the first argument is the same string as the second,
  618.     Xthen the value is the third argument.
  619.     XIf not, and if there are more than four arguments, the process is 
  620.     Xrepeated with arguments 4, 5, 6 and 7.
  621.     XOtherwise, the value is either the fourth string, or, if it is not present,
  622.     Xnull.
  623.     X.MC incr "(num)"
  624.     Xreturns the value of its argument incremented by 1.
  625.     XThe value of the argument is calculated
  626.     Xby interpreting an initial digit-string as a decimal number.
  627.     X.MC decr "(num)"
  628.     Xreturns the value of its argument decremented by 1.
  629.     X.MC eval "(expression)"
  630.     Xevaluates its argument as a constant expression, using integer arithmetic.
  631.     XThe evaluation mechanism is very similar to that of
  632.     X.I cpp
  633.     X(#if expression). 
  634.     XThe expression can involve only integer constants and character constants,
  635.     Xpossibly connected by the binary operators
  636.     X.nf
  637.     X.ft B
  638.     X
  639.     X*    /    %    +    -    >>    <<    <    >    
  640.     X<=    >=    ==    !=    &    ^    |    &&    ||
  641.     X
  642.     X.ft R
  643.     X.fi
  644.     Xor the unary operators \fB\- ~ !\fR
  645.     Xor by the ternary operator \fB ? : \fR.
  646.     XParentheses may be used for grouping. Octal numbers may be specified as
  647.     Xin C.
  648.     X.MC len "(string)"
  649.     Xreturns the number of characters in its argument.
  650.     X.MC index "(search-string, string)"
  651.     Xreturns the position in its first argument where the second argument 
  652.     Xbegins (zero origin),
  653.     Xor \-1 if the second argument does not occur.
  654.     X.MC substr "(string, index [, length])"
  655.     Xreturns a substring of its first argument.
  656.     XThe second argument is a zero origin
  657.     Xnumber selecting the first character (internally treated as an expression);
  658.     Xthe third argument indicates the length of the substring.
  659.     XA missing third argument is taken to be large enough to extend to
  660.     Xthe end of the first string. 
  661.     X.MC translit "(source, from [, to])"
  662.     Xtransliterates the characters in its first argument
  663.     Xfrom the set given by the second argument to the set given by the third.
  664.     XIf the third argument is shorter than the second, all extra characters
  665.     Xin the second argument are deleted from the first argument. If the third
  666.     Xargument is missing altogether, all characters in the second argument are
  667.     Xdeleted from the first argument.
  668.     X.MC include "(filename)"
  669.     Xreturns the contents of the file named in the argument.
  670.     X.MC sinclude "(filename)"
  671.     Xis identical to
  672.     X.IR include ,
  673.     Xexcept that it
  674.     Xsays nothing if the file is inaccessible.
  675.     X.MC paste "(filename)"
  676.     Xreturns the contents of the file named in the argument without any
  677.     Xprocessing, unlike 
  678.     X.IR include.
  679.     X.MC spaste "(filename)"
  680.     Xis identical to
  681.     X.IR paste ,
  682.     Xexcept that it says nothing if the file is inaccessible.
  683.     X.MC syscmd "(command)"
  684.     Xexecutes the
  685.     X.SM UNIX
  686.     Xcommand given in the first argument.
  687.     XNo value is returned.
  688.     X.MC sysval "()"
  689.     Xis the return code from the last call to
  690.     X.IR syscmd .
  691.     X.MC maketemp "(string)"
  692.     Xfills in a string of
  693.     X.SM XXXXXX
  694.     Xin its argument with the current process
  695.     X.SM ID\*S.
  696.     X.MC m4exit "([exitcode])"
  697.     Xcauses immediate exit from
  698.     X.IR m4 .
  699.     XArgument 1, if given, is the exit code;
  700.     Xthe default is 0.
  701.     X.MC m4wrap "(m4-macro-or-built-in)"
  702.     Xargument 1 will be pushed back at final
  703.     X.BR EOF ;
  704.     Xexample: m4wrap(`dumptable()').
  705.     X.MC errprint "(str [, str, str, ...])"
  706.     Xprints its argument(s) on stderr. If there is more than one argument,
  707.     Xeach argument is separated by a space during the output.
  708.     X.MC dumpdef "([name, name, ...])"
  709.     Xprints current names and definitions,
  710.     Xfor the named items, or for all if no arguments are given.
  711.     X.dt
  712.     X.SH AUTHOR
  713.     XOzan S. Yigit (oz)
  714.     X.SH BUGS
  715.     XPd M4 is distributed at the source level, and does not require an expensive
  716.     Xlicense agreement.
  717.     X.PP
  718.     XA sufficiently complex M4 macro set is about as readable
  719.     Xas
  720.     X.BR APL .
  721.     X.PP
  722.     XAll complex uses of M4 require the ability to program in deep recursion.
  723.     XPrevious lisp experience is recommended.
  724.     X.PP
  725.     XPd M4 is slower than V7 M4.
  726.     X.SH EXAMPLES
  727.     X.PP
  728.     XThe following macro program illustrates the type of things that
  729.     Xcan be done with M4. 
  730.     X.PP
  731.     X.RS
  732.     X.nf
  733.     X\fBchangequote\fR(<,>) \fBdefine\fR(HASHVAL,99) \fBdnl\fR
  734.     X\fBdefine\fR(hash,<\fBexpr\fR(str(\fBsubstr\fR($1,1),0)%HASHVAL)>) \fBdnl\fR
  735.     X\fBdefine\fR(str,
  736.     X    <\fBifelse\fR($1,",$2,
  737.     X        <str(\fBsubstr\fR(<$1>,1),<\fBexpr\fR($2+'\fBsubstr\fR($1,0,1)')>)>)
  738.     X    >) \fBdnl\fR
  739.     X\fBdefine\fR(KEYWORD,<$1,hash($1),>) \fBdnl\fR
  740.     X\fBdefine\fR(TSTART,
  741.     X<struct prehash {
  742.     X    char *keyword;
  743.     X    int   hashval;
  744.     X} keytab[] = {>) \fBdnl\fR
  745.     X\fBdefine\fR(TEND,<    "",0
  746.     X};>) \fBdnl\fR
  747.     X.fi
  748.     X.RE
  749.     X.PP
  750.     XThus a keyword table containing the keyword string and its pre-calculated
  751.     Xhash value may be generated thus:
  752.     X.PP
  753.     X.RS
  754.     X.nf
  755.     XTSTART
  756.     X    KEYWORD("foo")
  757.     X    KEYWORD("bar")
  758.     X    KEYWORD("baz")
  759.     XTEND
  760.     X.fi
  761.     X.RE
  762.     X.PP
  763.     Xwhich will expand into:
  764.     X.RS
  765.     X.nf
  766.     Xstruct prehash {
  767.     X    char *keyword;
  768.     X    int   hashval;
  769.     X} keytab[] = {
  770.     X    "foo",27,
  771.     X    "bar",12,
  772.     X    "baz",20,
  773.     X    "",0
  774.     X};
  775.     X.fi
  776.     X.RE
  777.     X.PP
  778.     XPresumably, such a table would speed up the installation of the
  779.     Xkeywords into a dynamic hash table. (Note that the above macro
  780.     Xcannot be used with 
  781.     X.IR M4 , 
  782.     Xsince 
  783.     X.B eval
  784.     Xdoes not handle character constants.)
  785.     X
  786.     X.SH SEE ALSO
  787.     Xcc(1),
  788.     Xm4(1),
  789.     Xcpp(1).
  790.     X.I "The M4 Macro Processor\^"
  791.     Xby B. W. Kernighan and D. M. Ritchie.
  792.     X
  793. SHAR_EOF
  794. if test 9644 -ne "`wc -c < 'm4.1'`"
  795. then
  796.     echo shar: error transmitting "'m4.1'" '(should have been 9644 characters)'
  797. fi
  798. fi # end of overwriting check
  799. #    End of shell archive
  800.